package ru.rchervot.sanasar.client.gin;

import ru.rchervot.sanasar.client.model.FactoryQuery;
import ru.rchervot.sanasar.client.model.FactoryQueryCandidates;
import ru.rchervot.sanasar.client.model.FactoryQueryCandidatesDefault;
import ru.rchervot.sanasar.client.place.FactoryPlace;
import ru.rchervot.sanasar.client.place.FactoryPlaceCandidates;
import ru.rchervot.sanasar.client.place.FactoryPlaceSettings;
import ru.rchervot.sanasar.client.place.ManagerPlaces;
import ru.rchervot.sanasar.client.place.ManagerPlacesDefault;
import ru.rchervot.sanasar.client.rpc.RPCServiceAsync;
import ru.rchervot.sanasar.client.view.FactoryModuleCandidates;
import ru.rchervot.sanasar.client.view.FactoryModuleCandidatesDefault;
import ru.rchervot.sanasar.client.view.FactoryModuleSettings;
import ru.rchervot.sanasar.client.view.FactoryModuleSettingsDefault;
import ru.rchervot.sanasar.client.view.FactorySearchHistoryView;
import ru.rchervot.sanasar.client.view.FactorySearchHistoryViewCandidates;
import ru.rchervot.sanasar.client.view.FactorySearchResultsView;
import ru.rchervot.sanasar.client.view.FactorySearchResultsViewCandidates;
import ru.rchervot.sanasar.client.view.RecordCandidatesPresenter;
import ru.rchervot.sanasar.client.view.RecordCandidatesView;
import ru.rchervot.sanasar.client.view.RecordEditCandidatesPresenter;
import ru.rchervot.sanasar.client.view.RecordEditCandidatesView;
import ru.rchervot.sanasar.client.view.RecordEditPresenter;
import ru.rchervot.sanasar.client.view.RecordPresenter;
import ru.rchervot.sanasar.client.view.RecordSummaryCandidatesPresenter;
import ru.rchervot.sanasar.client.view.ResultsCandidatesPresenter;
import ru.rchervot.sanasar.client.view.ResultsCandidatesView;
import ru.rchervot.sanasar.client.view.RootPresenter;

import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.inject.client.AbstractGinModule;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.google.inject.name.Names;

@Singleton // that means that this class is thread safe - is it?
public class GinjectorViewModule extends AbstractGinModule {
	
	public GinjectorViewModule() {
	}

	
	@Override
  protected void configure() {

  	bind(ResultsCandidatesPresenter.Display.class).to(ResultsCandidatesView.class).in(Singleton.class);
  	bind(RecordCandidatesPresenter.Display.class).to(RecordCandidatesView.class).in(Singleton.class);
  	bind(RecordEditCandidatesPresenter.Display.class).to(RecordEditCandidatesView.class).in(Singleton.class);
  	bind(RecordSummaryCandidatesPresenter.Display.class).toProvider(ProviderResultsItemCandidatesView.class);
  	
  	bind(RootPresenter.class).toProvider(ProviderRootPresenter.class).in(Singleton.class);
  	bind(RecordEditPresenter.class).toProvider(ProviderRecordEditPresenterCandidates.class).in(Singleton.class);
  	bind(RecordPresenter.class).toProvider(ProviderRecordPresenterCandidates.class).in(Singleton.class);
  	
  	bind(HandlerManager.class).toProvider(ProviderHandlerManager.class).in(Singleton.class);
  	bind(RPCServiceAsync.class).toProvider(ProviderService.class).in(Singleton.class);
  	
  	
  	bind(FactorySearchHistoryView.class).to(FactorySearchHistoryViewCandidates.class).in(Singleton.class);
  	bind(FactorySearchResultsView.class).to(FactorySearchResultsViewCandidates.class).in(Singleton.class);
  	
  	
  	bind(FactoryModuleCandidatesDefault.class).in(Singleton.class);
  	bind(FactoryModuleCandidates.class).to(FactoryModuleCandidatesDefault.class);
  	
  	bind(FactoryModuleSettingsDefault.class).in(Singleton.class);
  	bind(FactoryModuleSettings.class).to(FactoryModuleSettingsDefault.class);
  	
  	bind(Widget.class)
  	.annotatedWith(Names.named("ResultsWidget"))
  	.to(HTML.class).in(Singleton.class);
  	
  	bind(FactoryQueryCandidatesDefault.class).in(Singleton.class);
  	bind(FactoryQuery.class).to(FactoryQueryCandidatesDefault.class).in(Singleton.class);
  	bind(FactoryQueryCandidates.class).to(FactoryQueryCandidatesDefault.class).in(Singleton.class);
  	
  	//Places
  	bind(ManagerPlaces.class).to(ManagerPlacesDefault.class).in(Singleton.class);
  	
  	bind(FactoryPlace.class)
  	.annotatedWith(Names.named("Candidates"))
  	.to(FactoryPlaceCandidates.class).in(Singleton.class);
  	bind(FactoryPlace.class)
  	.annotatedWith(Names.named("Settings"))
  	.to(FactoryPlaceSettings.class).in(Singleton.class);
  }
	
	@Provides @Singleton
	Widget getWidget() {
		return new HTML("HTML");
	}

}
